import 'package:flutter/material.dart';
import './page/home.dart';
import './page/email.dart';
import './page/pages.dart';
import './page/airplay.dart';

class BottomNavigationWidget extends StatefulWidget {
  const BottomNavigationWidget({Key? key}) : super(key: key);

  @override
  _BottomNavigationWidgetState createState() => _BottomNavigationWidgetState();
}

class _BottomNavigationWidgetState extends State<BottomNavigationWidget> {
  int _currentIndex = 0;
   List<Widget> list = [];

  @override
  void initState() {
    list..add(HomeScreen())..add(EmailScreen())..add(PagesScreen())..add(AirplayScreen());
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // body引入子页面的作为body
      body: list[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home, color: _currentIndex==0?Theme.of(context).primaryColor:Theme.of(context).unselectedWidgetColor),
            label: 'Home',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.email, color: _currentIndex==1?Theme.of(context).primaryColor:Theme.of(context).unselectedWidgetColor),
            label: 'Email',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.pages, color: _currentIndex==2?Theme.of(context).primaryColor:Theme.of(context).unselectedWidgetColor),
            label: 'Pages',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.airplay, color: _currentIndex==3?Theme.of(context).primaryColor:Theme.of(context).unselectedWidgetColor),
            label: 'AirPlay',
          )
        ],
        // 当前索引
        currentIndex: _currentIndex,
        // 点击事件
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}
